package com.ruoyi.house_sale.controller;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.house_sale.domain.ProjectInfo;
import com.ruoyi.house_sale.service.IProjectInfoService;
import com.ruoyi.house_sale.service.ITerminfoService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.house_sale.domain.Terminfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 楼栋资料Controller
 * 
 * @author ruoyi
 * @date 2022-03-28
 */
@RestController
@RequestMapping("/house_sale/terminfo")
public class TerminfoController extends BaseController
{
    @Autowired
    private ITerminfoService terminfoService;
    @Resource
    private IProjectInfoService projectInfoService;
    /**
     * 查询楼栋资料列表
     */
    @PreAuthorize("@ss.hasPermi('house_sale:terminfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(Terminfo terminfo)
    {
        startPage();
        List<Terminfo> list = terminfoService.selectTerminfoList(terminfo);
        return getDataTable(list);
    }
    @GetMapping("/projectList")
    public AjaxResult projectList(){

        List<ProjectInfo> list = projectInfoService.findAllProject();
        AjaxResult ajax = AjaxResult.success();
        ajax.put("projectList", list);
        return ajax;
    }


    /**
     * 导出楼栋资料列表
     */
    @PreAuthorize("@ss.hasPermi('house_sale:terminfo:export')")
    @Log(title = "楼栋资料", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Terminfo terminfo)
    {
        List<Terminfo> list = terminfoService.selectTerminfoList(terminfo);
        ExcelUtil<Terminfo> util = new ExcelUtil<Terminfo>(Terminfo.class);
        util.exportExcel(response, list, "楼栋资料数据");
    }

    /**
     * 获取楼栋资料详细信息
     */
    @PreAuthorize("@ss.hasPermi('house_sale:terminfo:query')")
    @GetMapping(value = "/{termid}")
    public AjaxResult getInfo(@PathVariable("termid") Long termid)
    {
        List<ProjectInfo> list = projectInfoService.findAllProject();
        Terminfo terminfo= terminfoService.selectTerminfoByTermid(termid);
        AjaxResult ajax = AjaxResult.success();
        ajax.put("projectList", list);
        ajax.put("terminfo", terminfo);

        return ajax;
       // return AjaxResult.success();
    }

    /**
     * 新增楼栋资料
     */
    @PreAuthorize("@ss.hasPermi('house_sale:terminfo:add')")
    @Log(title = "楼栋资料", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Terminfo terminfo)
    {
        return toAjax(terminfoService.insertTerminfo(terminfo));
    }

    /**
     * 修改楼栋资料
     */
    @PreAuthorize("@ss.hasPermi('house_sale:terminfo:edit')")
    @Log(title = "楼栋资料", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Terminfo terminfo)
    {
        return toAjax(terminfoService.updateTerminfo(terminfo));
    }

    /**
     * 删除楼栋资料
     */
    @PreAuthorize("@ss.hasPermi('house_sale:terminfo:remove')")
    @Log(title = "楼栋资料", businessType = BusinessType.DELETE)
	@DeleteMapping("/{termids}")
    public AjaxResult remove(@PathVariable Long[] termids)
    {
        return toAjax(terminfoService.deleteTerminfoByTermids(termids));
    }
}
